(function($){
	$(function(){
		var oSeachContent = $("#mq");
		var oLabel = $("#mq1 label");
		var oSearchList   = $('#show');
		var iSearchIndex = -1;

		oSeachContent.focus(function(){
			oLabel.css("color","rgb(204, 204,204)");
			if($(this).val()){
				oSearchList.css("display","block");
			}else{
				
			}
		}).blur(function(){
			if($(this).val()){
				
			}else{
				oLabel.css({"color":"rgb(102, 102,102)","display":"block"});
			}
			oSearchList.css("display","none");
		}).keyup(function(e){
			oLabel.css("display","none");
			var
				ev = ev || window.event,
				aLi = $('#show li');
				
			if(ev.keyCode === 38 || ev.keyCode === 40) {
				if(ev.keyCode === 38 && iSearchIndex > 0) {
					iSearchIndex--;
				} else if(ev.keyCode === 38 && iSearchIndex<=0){
					iSearchIndex = aLi.length - 1;
				}
				
				if(ev.keyCode === 40 && iSearchIndex < aLi.length - 1) {
					iSearchIndex++;
				}
				else if(ev.keyCode === 40 && iSearchIndex >= aLi.length - 1){
					iSearchIndex = 0;
				}
				oSeachContent.val(aLi.removeClass('active').eq(iSearchIndex).addClass('active').data('key'));
			}
		}).bind('input propertychange', function () {
			oLabel.css("display","none");
			var sSearchCon = $(this).val();
			if(sSearchCon) {
				$.ajax({
					url: 'https://suggest.taobao.com/sug',
					data: {q: sSearchCon,
							area:"b2c",
							code:"utf-8",
							k:1,
							bucketid:11,
							src:"tmall_pc"
					},
					jsonp: 'callback',
					//jsonpCallback: 'jsonp609',
					dataType: 'jsonp',
					success: function (data) {
						//console.log(data.result);
						var sHtml = '';
						data.result.forEach(function (v) {
							sHtml += '<li data-key="' + v[0] + '"><a href="javascript:;"><span>约有' + v[1] + '个结果</span><b>' + v[0] + '</b></a></li>';
						});
						sHtml += '<li><i></i><div>找<em>\"'+sSearchCon+'\"</em>相关<b>店铺</b></div></li>'
						if(sHtml) {
							oSearchList.css('display', 'block').html(sHtml);
						} else {
							oSearchList.css('display', 'none');
						}
						iSearchIndex = -1;
						$('#show li').mouseover(function(i){
							var oIndex = $(this).index();
							//console.log(oIndex);
							$('#show li').removeClass("active").eq(oIndex).addClass("active");
							iSearchIndex = oIndex;
						})
					}
					
				});
				
			} else {
				if($(this).val()){
					sHtml += '<li><i></i><div>找<em>\"'+sSearchCon+'\"</em>相关<b>店铺</b></div></li>'
				}else{
					oSearchList.css("display","none");
				}
				
				iSearchIndex = -1;
			}
		});

	var nav1 =  $(".lou1");
		var oTxt = $(".txt1");
	
	$(window).scroll(function(){
		
		var scroll = $(window).scrollTop();
		var clientX = $(window).height();
		var zonghe = scroll + clientX/2;
			//console.log(scroll);
		if(scroll>=500){
			$("#top").stop(true,true).fadeTo(500,1);
			$("#topbg").stop(true,true).fadeTo(500,0.9);
			
		}else{
			$("#top").stop(true,true).fadeTo(500,0);
			$("#topbg").stop(true,true).fadeTo(500,0);
				
		}
		var oTxt = $(".txt1");
		var nav1 =  $(".lou1");
		if(scroll>=400){
			$("#lou").css("display","block").stop().animate({
				width:35,
				height:370
			},500);
		}else{
			$("#lou").stop().animate({
				width:0,
				height:0
			},500).css("display","none");
		}
		//console.log($("#content .txt1"));
		
		
		oTxt.each(function(){
			var index = $(this).index()-2;
			var offTop = $(this).offset().top;
			var height = $(this).height() + offTop;
			//console.log(offLeft)
			//console.log(index,height,zonghe);
			if( zonghe>offTop && zonghe < height){
				//console.log(oTxt.eq(index))
				nav1.css("background","#666");
				
				switch(index){
					case 0:	nav1.eq(index).css("background","#19C8A9") ; break;
					case 1: nav1.eq(index).css("background","#EA5F8D") ; break;
					case 2: nav1.eq(index).css("background","#0AA6E8") ; break;
					case 3: nav1.eq(index).css("background","#F7A945") ; break;
					case 4: nav1.eq(index).css("background","#F15453") ; break;
					case 5: nav1.eq(index).css("background","#64C333") ; break;
					case 6: nav1.eq(index).css("background","#DD2727") ; break;
					case 7: nav1.eq(index).css("background","#DD2727") ; break;
					
				}
				
			}
		})
		
//			
	})

		nav1.click(function(){
		var aindex = $(this).index()-1;
		var scroll = oTxt.eq(aindex).offset().top;
		console.log(scroll,$(window).scrollTop); 
		$(window).scrollTop(scroll-50);
		console.log(scroll);
		})
	
	

})
})(jQuery)



















